---
title: "Hibernate 实现的JPA处理java.time.LocalDateTime的跟踪"
date: 2020-2-27
categories:
- java
- spring-jpa
tags:
---

<div id="content">
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org08b4443">时区配置</a>
<ul>
<li><a href="#org2e65f7e">Spring</a></li>
</ul>
</li>
<li><a href="#org3644ee7">调用堆栈</a>
<ul>
<li><a href="#org774243e">存储时</a></li>
<li><a href="#orge49ffa1">读取时，调用的是Wrap方法</a></li>
</ul>
</li>
<li><a href="#org7d7ac2f">过程</a></li>
</ul>
</div>
</div>
<div class="outline-2" id="outline-container-org08b4443">
<h2 id="org08b4443">时区配置</h2>
<div class="outline-text-2" id="text-org08b4443">
<p>
连接字符串上指定时区
</p>
</div>
<div class="outline-3" id="outline-container-org2e65f7e">
<h3 id="org2e65f7e">Spring</h3>
<div class="outline-text-3" id="text-org2e65f7e">
<div class="org-src-container">
<pre class="src src-yml">spring:
  jpa:
    properties:
      hibernate:
	jdbc:
	  time_zone: Asia/Shanghai
</pre>
</div>
</div>
</div>
</div>
<div class="outline-2" id="outline-container-org3644ee7">
<h2 id="org3644ee7">调用堆栈</h2>
<div class="outline-text-2" id="text-org3644ee7">
</div>
<div class="outline-3" id="outline-container-org774243e">
<h3 id="org774243e">存储时</h3>
<div class="outline-text-3" id="text-org774243e">
<p>
Hibernate version: 5.4.10.Fianl
</p>
<p>
doBind:48, TimestampTypeDescriptor$1 (org.hibernate.type.descriptor.sql)
bind:73, BasicBinder (org.hibernate.type.descriptor.sql)
nullSafeSet:276, AbstractStandardBasicType (org.hibernate.type)
nullSafeSet:271, AbstractStandardBasicType (org.hibernate.type)
nullSafeSet:39, AbstractSingleColumnStandardBasicType (org.hibernate.type)
dehydrate:2920, AbstractEntityPersister (org.hibernate.persister.entity)
dehydrate:2895, AbstractEntityPersister (org.hibernate.persister.entity)
bindValues:3116, AbstractEntityPersister$4 (org.hibernate.persister.entity)
performInsert:42, AbstractReturningDelegate (org.hibernate.id.insert)
insert:3124, AbstractEntityPersister (org.hibernate.persister.entity)
insert:3728, AbstractEntityPersister (org.hibernate.persister.entity)
execute:84, EntityIdentityInsertAction (org.hibernate.action.internal)
execute:645, ActionQueue (org.hibernate.engine.spi)
addResolvedEntityInsertAction:282, ActionQueue (org.hibernate.engine.spi)
addInsertAction:263, ActionQueue (org.hibernate.engine.spi)
addAction:317, ActionQueue (org.hibernate.engine.spi)
addInsertAction:335, AbstractSaveEventListener (org.hibernate.event.internal)
performSaveOrReplicate:292, AbstractSaveEventListener (org.hibernate.event.internal)
performSave:198, AbstractSaveEventListener (org.hibernate.event.internal)
saveWithGeneratedId:128, AbstractSaveEventListener (org.hibernate.event.internal)
entityIsTransient:192, DefaultPersistEventListener (org.hibernate.event.internal)
onPersist:135, DefaultPersistEventListener (org.hibernate.event.internal)
onPersist:62, DefaultPersistEventListener (org.hibernate.event.internal)
accept:-1, 825935118 (org.hibernate.internal.SessionImpl$$Lambda$1171)
fireEventOnEachListener:108, EventListenerGroupImpl (org.hibernate.event.service.internal)
firePersist:702, SessionImpl (org.hibernate.internal)
persist:688, SessionImpl (org.hibernate.internal)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
invoke:314, SharedEntityManagerCreator$SharedEntityManagerInvocationHandler (org.springframework.orm.jpa)
persist:-1, $Proxy184 (com.sun.proxy)
save:554, SimpleJpaRepository (org.springframework.data.jpa.repository.support)
saveAll:588, SimpleJpaRepository (org.springframework.data.jpa.repository.support)
saveAll:78, SimpleJpaRepository (org.springframework.data.jpa.repository.support)
</p>
<p>
doBind方法中有一个javaTypeDescriptor将时间处理成了java.sql.Timestamp.
</p>
<p>
javaTypeDescriptor的类型是org/hibernate/type/descriptor/java/LocalDateTimeJavaDescriptor.java
</p>
</div>
</div>
<div class="outline-3" id="outline-container-orge49ffa1">
<h3 id="orge49ffa1">读取时，调用的是Wrap方法</h3>
</div>
</div>
<div class="outline-2" id="outline-container-org7d7ac2f">
<h2 id="org7d7ac2f">过程</h2>
</div>
</div>
<div class="status" id="postamble">
<p class="date">Date: 2020-2-27</p>
<p class="author">Author: gdme1320</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
